package com.tcm.portal.web.controller;

import com.base.core.utils.R;
import com.search.service.SearchHospitalService;
import com.search.service.dto.SearchHospitalParam;
import com.tcm.core.service.HospitalService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/portal/hospital")
@RestController
public class HospitalController {

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private HospitalService hospitalService;

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private SearchHospitalService searchHospitalService;

    /**
     * 获取单条记录
     *
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/view")
    public R view(@RequestParam("id") Long id) throws Exception {
        return R.success(hospitalService.findHospitalById(id));
    }

    /**
     * 分页查询医院数据
     *
     * @param page
     * @param pagesize
     * @return
     * @throws Exception
     */
    @GetMapping("/list/page")
    public R listPage(@RequestParam(defaultValue = "0") Long page,
                      @RequestParam(defaultValue = "10") Long pagesize) throws Exception {
        return R.success(hospitalService.listHospitalPage(page, pagesize));
    }

    /**
     * 分页搜索医院数据
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/list/search/page")
    public R listSearchPage(SearchHospitalParam searchHospitalParam) throws Exception {
        return R.success(searchHospitalService.search(searchHospitalParam));
    }

}
